<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin pro - 通用后台管理模板系统（单页面专业版）</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/admin/css/style.css">
    <script src="__STATIC__/lib/layui/layui.js" ></script>
    <script src="__STATIC__/admin/js/jquery-3.3.1.js"></script>
    <link id="layuicss-layuiAdmin" rel="stylesheet" href="__STATIC__/admin/css/admin.css" media="all">
</head>
<body layadmin-themealias="default" class="layui-layout-body" style="">
<div id="LAY_app" class="layadmin-tabspage-none">
    <div class="layui-layout layui-layout-admin">
        <!--头部文件-->
        {include file="common/header"/}
        <!--左侧导航栏-->
        {include file="common/left"/}

        <!-- 主体内容 -->
        <div class="layui-body" id="LAY_app_body">
            <div class="layadmin-tabsbody-item layui-show">
                <div class="layui-card layadmin-header">
                    <div class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
                        <a lay-href="">主页</a><span lay-separator="">/</span>
                        <a><cite>用户管理</cite></a><span lay-separator="">/</span>
                        <a><cite>管理员管理</cite></a>
                    </div>
                </div>


                <div class="layui-fluid">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <span>管理员信息</span>
                            <a href="{:url('admin/add')}" class="layui-btn layui-btn-sm">
                              <i class="layui-icon"></i>增加管理员
                            </a>

                        </div>

                        <div class="layui-form">
                            <table class="layui-table">
                                <thead>
                                <tr>
                                    <!--<th>-->
                                        <!--<div class="layui-unselect layui-form-checkbox all-check" lay-skin="primary" >-->
                                            <!--<i class="layui-icon layui-icon-ok"></i>-->
                                        <!--</div>-->
                                    <!--</th>-->
                                    <th>序号</th>
                                    <th>用户名</th>
                                    <th>角色</th>
                                    <th>联系电话</th>
                                    <th>上次登陆IP</th>
                                    <th>上次登陆时间</th>
                                    <th>用户状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {foreach $admins as $vo}
                                <tr>
                                    <!--<td>-->
                                        <!--<div class="layui-unselect layui-form-checkbox check " name="admins[]" onclick="javascript:$(this).toggleClass('layui-form-checked');" lay-skin="primary">-->
                                            <!--<i class="layui-icon layui-icon-ok"></i>-->
                                        <!--</div>-->
                                    <!--</td>-->
                                    <td>{$vo['id']}</td>
                                    <td>{$vo['username']}</td>
                                    <td>{$vo['name']}</td>
                                    <td>{$vo['phone']}</td>

                                    {if condition="$vo['last_ip'] neq ''"}
                                    <td>{$vo['last_ip']} </td>
                                    {else/}
                                    <td>暂未登陆</td>
                                    {/if}

                                    {if condition="$vo['login_time'] neq ''"}
                                    <td>{$vo['login_time']|date="Y-m-d H:i:s",###} </td>
                                    {else/}
                                    <td>暂未登陆</td>

                                    {/if}
                                    {if condition="$vo['status'] eq 1"}
                                    <td><span style="color: green;">正常</span></td>
                                    {else/}
                                    <td><span style="color: red;">锁定</span></td>
                                    {/if}
                                    <td>
                                        <div class="layui-table-cell ">
                                            <a class="layui-btn layui-btn-normal layui-btn-xs edit" lay-event="" href="{:url('admin/edit',['id'=>$vo['id']])}">
                                                <i class="layui-icon layui-icon-edit"></i>
                                                编辑
                                            </a>
                                            <a class="layui-btn layui-btn-danger layui-btn-xs del " vo="{$vo['id']}">
                                                <i class="layui-icon layui-icon-delete"></i>删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {/foreach}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div style="width: 100%;text-align: right">
                        {$page}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


</body>

<script>

    $(function () {
        //删除管理员
        $('.del').click(function () {
            var that=this;
            var id=$(this).attr('vo');
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.open({
                    type: 0
                    ,title:'警告'
                    ,offset: 'auto'
                    ,content: '您确认要删除吗?'
                    // ,btnAlign: 'c' //按钮居中
                    ,btn: ["确认","取消"]
                    ,yes: function(){
                        $.post("{:url('del')}",{'id':id},function (json) {
                            layer.closeAll();
                            if(json.code==1){
                                layer.msg(json.msg,{icon:1});
                                $(that).parent().parent().parent().remove();
                            }else {
                                layer.msg(json.msg,{icon:5});
                            }
                        });
                    }
                    ,no:function () {
                        layer.closeAll();
                    }
                });

            });
        });
        //多选
        $('.all-check').click(function () {
            $(this).toggleClass('layui-form-checked');
            $(".check").toggleClass('layui-form-checked')
        });


        //添加管理员
        $('.add_admin').click(function () {
            $('.add_admin_info').toggle();
        });

        layui.use('form',function () {
            var form=layui.form;layer=layui.layer;
            form.render();
            //监听提交事件
            form.on("submit(sub)",function (data) {
                //进行数据的提交
                $.post("{:url('admin/add')}",data.field,function (res) {

                console.log(res);

                    if(res.code==1){
                        layer.msg(res.msg,{icon:1,time:3000},function () {

                            //自动增加一行数据
                            $('.layui-table tbody').append(
                                "<tr>\n" +
                                "    <td>\n" +
                                "        <div class=\"layui-unselect layui-form-checkbox \" lay-skin=\"primary\">\n" +
                                "            <i class=\"layui-icon layui-icon-ok\"></i>\n" +
                                "        </div>\n" +
                                "    </td>\n" +
                                "    <td>"+res.re.id+"</td>\n" +
                                "    <td>"+res.re.username+"</td>\n" +
                                "    <td>"+res.re.role_id+"</td>\n" +
                                "    <td>"+res.re.phone+"</td>\n" +
                                "    <td>"+res.re.last_ip+"</td>\n" +
                                "    <td>"+res.re.login_time+"</td>\n" +
                                "    <td>"+res.re.status+"</td>\n" +
                                "    <td>\n" +
                                "        <div class=\"layui-table-cell \">\n" +
                                "            <a class=\"layui-btn layui-btn-normal layui-btn-xs edit\" lay-event=\"edit\">\n" +
                                "                <i class=\"layui-icon layui-icon-edit\"></i>\n" +
                                "                编辑\n" +
                                "            </a>\n" +
                                "            <a class=\"layui-btn layui-btn-danger layui-btn-xs del \" vo=\"+res.re.id+\">\n" +
                                "                <i class=\"layui-icon layui-icon-delete\"></i>删除\n" +
                                "            </a>\n" +
                                "        </div>\n" +
                                "    </td>\n" +
                                "</tr>"
                            );

                            $('.add_admin_info').hide();

                        });
                    }else {
                        layer.msg(res.msg,{icon:5,time:2000},function () {
                           return false;

                        });
                    }

                });
                return false;
            });

            return false;


        });


    });




</script>


</html>